import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        Client client = new Client();
        String TOKEN = client.isAvailable();

        // 检查支付接口是否可用并获取token
        if (TOKEN != null) {
            System.out.println("支付接口可用，Token已获取。");

            // 进行支付操作，并等待回调
            double amountToPay = 10.00;
            client.pay(amountToPay, new PaymentCallback() {
                @Override
                public void onPaymentSuccess(String orderId) throws IOException {
                    System.out.println("支付成功！订单ID: " + orderId);

                    // 使用获取的orderId查询订单
                    String orderResponse = client.query(orderId);
                    System.out.println("订单查询结果: " + orderResponse);
                }

                @Override
                public void onPaymentFailure(String errorMessage) {
                    System.out.println("支付失败！错误消息: " + errorMessage);
                }
            });

            // 进行退款查询操作
            double amountToRefund = 5.00; // 假设退款金额为5元
            client.refunds(amountToPay, new RefundCallback() {
                @Override
                public void onRefundSuccess(String refundId) throws IOException {
                    System.out.println("退款成功！退款单ID: " + refundId);

                    // 使用获取的orderId查询订单
                    String refundResponse = client.queryRefunds(refundId);
                    System.out.println("退款单查询结果: " + refundResponse);
                }

                @Override
                public void onRefundFailure(String errorMessage) {
                    System.out.println("退款失败！错误消息: " + errorMessage);
                }
            });
        } else {
            System.out.println("支付接口不可用，无法获取Token。");
        }
    }
}
